package cz.vutbr.fit.dnacompress.events;

import org.biojava.utils.ParserException;

/**
 * obecny AlignEvent object
 */
public class AlignEvent {
	
	/**
	 * mody eventu
	 */
	private static final int MODE_POSITION = 0;
	private static final int MODE_INTERVAL = 1;
	
	/**
	 * enum pro vytovreni typu Eventu na zaklade identifikacniho stringu (tabulka poctu)
	 */
	public enum EventClasses {
		Mut, Del, Ins;

		private static AlignEvent getClass( String str){
			
			EventClasses type = valueOf( str);
			switch( type) {
				case Mut: return new AlignMutationEvent(0);
				case Del: return new AlignDeletitionEvent(0);
				case Ins: return new AlignInsertionEvent(0);
			}
			throw new AssertionError("Unknown event class: " + type);
		}
	}
	
	/**
	 * Vrati tridu eventu podle daneho stringu
	 * povolene retezce jsou:
	 * 	Mut - AlignMutationEvent
	 *  Del - AlignDeletitionEvent
	 *  Ins - AlignInsertionEvent
	 *  
	 * @param str
	 * @return AlignEvent
	 */
	public static AlignEvent getClass( String str) {
		
		return EventClasses.getClass( str);
	}
	
	/**
	 * Vrati tridu eventu podle daneho stringu, ktery obsahuje identifikator tridy a data
	 * povolene retezce jsou:
	 * 	Mut-a - AlignMutationEvent
	 *  Del-1 - AlignDeletitionEvent
	 *  Ins-ac - AlignInsertionEvent
	 *  
	 * @param str
	 * @return AlignEvent
	 */
	public static AlignEvent getClassWithData( String str) throws ParserException {
		
		String[] eventStrings = str.split("-");
		if( eventStrings.length != 2) {
			throw new ParserException( "Wrong column count in countTable!");
		}
		AlignEvent event = getClass( eventStrings[0]);
		event.setData( eventStrings[1]);
		
		return event;
	}
	
	/**
	 * separator mezi pozici a data
	 */
	protected String separator = "";
	
	/**
	 * separator na konci dat
	 */
	protected String end = "";
	
	/**
	 * pozice eventu
	 */
	private int position;
	
	/**
	 * pocet eventu pro tabulku poctu
	 */
	private int count = 0;
	
	/**
	 * defaultni mod
	 */
	private int mode = MODE_INTERVAL;
	
	/**
	 * kratky identifikator tridy
	 */
	private String shortClass;
	
	/**
	 * prenasena data
	 */
	protected String data;
	
	public AlignEvent( int position) {
		
		setPosition( position);
	}
	
	public AlignEvent( int position, int mode) {
		
		setPosition(position);
		setMode(mode);
	}

	/**
	 * 
	 * @return int
	 */
	public int getMode() {
		return mode;
	}

	/**
	 * 
	 * @param int mode
	 */
	public void setMode(int mode) {
		this.mode = mode;
	}

	/**
	 * 
	 * @return int
	 */
	public int getPosition() {
		return position;
	}

	/**
	 * 
	 * @param int position
	 */
	public void setPosition(int position) {
		this.position = position;
	}

	/**
	 * 
	 * @return String
	 */
	public String getData() {
		return data;
	}

	/**
	 * 
	 * @param String data
	 */
	public void setData(String data) {
		this.data = data;
	}
	
	/**
	 * Data jako cislo (Deletition)
	 * 
	 * @param int data
	 */
	public void setData(int data) {
		this.data = Integer.toString( data);
	}
	
	/**
	 * not impelemented
	 */
	public void addData() {}
	
	/**
	 * pripojeni noveho znaku k datum
	 * @param char data
	 */
	public void addData( char data) {
		
		this.addData( Character.toString( data));
	}
	
	/**
	 * pripojeni noveho retezce k datum
	 * 
	 * @param String data
	 */
	public void addData( String data) {
		if( this.data == null) {
			this.data = data;
		} else {
			this.data += data;
		}
	}
	
	/**
	 * vrati data obalena separatory
	 * 
	 * @return String
	 */
	public String getSeparedData() {
		
		return separator + this.data + end;
	}
	
	/**
	 * vrati pozici + separovana data (100iAAA)
	 */
	public String toString() {
		return this.position + this.getSeparedData(); 
	}

	/**
	 * @return the count
	 */
	public int getCount() {
		return count;
	}

	/**
	 * @param count the count to set
	 */
	public void setCount(int count) {
		this.count = count;
	}
	
	/**
	 * inkrementace poctu pro tabulku poctu
	 */
	public void incrementCount() {
		
		this.count++;
	}

	/**
	 * @return the shortClass
	 */
	public String getShortClass() {
		return shortClass;
	}

	/**
	 * @param shortClass the shortClass to set
	 */
	public void setShortClass(String shortClass) {
		this.shortClass = shortClass;
	}
	
	/**
	 * Vraci identifikator pro countTable
	 * 
	 * @return String
	 */
	public String getCountID() {
		
		return this.getShortClass() + "-" + this.getData();
	}
	
	
}
